//
//  PlayerCell.m
//  SimpleHappy
//
//  Created by lanou on 15/11/23.
//  Copyright © 2015年 RockyFung. All rights reserved.
//

#import "PlayerCell.h"
#import "Define.h"
#import "DIYButton.h"
#import "UIImageView+WebCache.h"

@interface PlayerCell()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *virtualName; // 作者名字
@property (nonatomic, strong) UIView *blackView;
@property (nonatomic, strong) UIImageView *iconImage; // 作者头像
@property (nonatomic, strong) DIYButton *wish;
@property (nonatomic, strong) UIImageView *bgView;

@end

@implementation PlayerCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = NO;
        
        
        CGFloat width = KScreenWidth - 10;
        CGFloat height = width / 640 * 330;
        
        //        self.frame.size.height
        // 添加背景图片
        self.bgView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, width, height )];
        self.bgView.image= [UIImage imageNamed:@"001"];
        [self.contentView addSubview:_bgView];
        
        // 添加黑色半透明效果
        self.blackView = [[UIView alloc]initWithFrame:_bgView.frame];
        self.blackView.backgroundColor = [UIColor blackColor];
        self.blackView.alpha = 0.3;
        [self.contentView addSubview:_blackView];
        
        
        // 头像边长
        CGFloat bc = KScreenWidth / 10.7;
        // 间距
        CGFloat juli = KScreenWidth / 7.5;
        
        // 添加头像
        self.iconImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, height - juli, bc, bc)];
        self.iconImage.image = [UIImage imageNamed:@"01.jpg"];
        self.iconImage.layer.cornerRadius = bc / 2;
        self.iconImage.layer.masksToBounds = YES;
        [self.contentView addSubview:_iconImage];
        
        // 添加label
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(juli, height/1.5, width-juli, height/7)];
        self.titleLabel.text = @"";
        self.titleLabel.font = [UIFont boldSystemFontOfSize:KScreenWidth / 20.8];
        self.titleLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_titleLabel];
        
        self.virtualName = [[UILabel alloc]initWithFrame:CGRectMake(juli, height/1.2, width-juli, height/8)];
        self.virtualName.text = @" ";
        self.virtualName.font = [UIFont systemFontOfSize:KScreenWidth / 25];
        self.virtualName.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_virtualName];
        
        // 添加心愿
        self.wish = [[DIYButton alloc]initWithFrame:CGRectMake(width - KScreenWidth / 5.5, height/1.2, KScreenWidth / 4.7, KScreenWidth / 18.75)];
        self.wish.iconImageView.image = [UIImage imageNamed:@"aixin3"];
        self.wish.textLabel.text = @" ";
        [self.contentView addSubview:_wish];
        

    }
    return self;
}


- (void)setModel:(PlayerModel *)model
{
    _model = model;
    
    // 设置背景图片
    [self.bgView sd_setImageWithURL:[NSURL URLWithString:self.model.picUrl]];
    
    // 标题
    self.titleLabel.text = self.model.title;
    
    // 作者头像
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:self.model.virtualPhotoUrl]];
    
    // 作者名字
    self.virtualName.text = self.model.virtualName;
    
    // 兴趣数量
    self.wish.textLabel.text = self.model.interestedNum;
    
}

@end
